#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e5;
int t,n,a[maxn],b[maxn],ans,temp;
bool vis[maxn],flag=0;
int dfs(int score,int step){
	if(step==n+1) return score;
		vis[1]=0;
		for(int i=2;i<=n;i++){
	         for(int j=i;j>=1;j--){
				 if(vis[i]==0){
					 if(vis[j]==vis[i]){
					     flag=1;
					     temp=j;
					     //cout<<temp<<endl;
					     break;
				     }
				     if(flag==0) dfs(score,step+1); 
				     if(flag==1&&a[temp]==a[i]){
					     dfs(score+a[temp],step+1);
				     }
				     else if(flag==1&&a[temp]!=a[step]){
					     dfs(score,step+1); 
				     }
				 }
				 else if(vis[i]==1){
					 
					     if(vis[j]==vis[i]){
					         flag=1;
					         temp=j;
					         break;
				         }
					 }
				     if(flag==0) dfs(score,step+1); 
				     if(flag==1&&a[temp]==a[i]){
					     dfs(score+a[temp],step+1);
				     }
				     else if(flag==1&&a[temp]!=a[step]){
					     dfs(score,step+1); 
				     }
			 }
		}
		return ans=score;
}
int main(){
    freopen("color.in","r",stdin);
   freopen("color.out","w",stdout);
    cin>>t;
    while(t--){
        int sum=0;
		cin>>n;
		for(int i=1;i<=n;i++){
			cin>>a[i];
			b[a[i]]++;
		}
		for(int i=1;i<=n;i++){
			if(b[a[i]]==1) sum++;
			if(sum==n) cout<<"0"<<endl;
		}
		cout<<dfs(0,1)<<endl;
	}
	return 0;
}
